package com.itbaizhan.springsecuritydemo1.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

import javax.sql.DataSource;
@Configuration
public class RememberMeConfig {
    //引入数据源
    @Autowired
    private DataSource dataSource;
    
    //设置令牌
    @Bean
    public PersistentTokenRepository persistentTokenRepository (){
        JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();
        //链接数据源
        jdbcTokenRepository.setDataSource(dataSource);
        //自动建表
//        jdbcTokenRepository.setCreateTableOnStartup(true);
        return jdbcTokenRepository;
    }
    
    @Bean
    //注入session注册器
    public SessionRegistry sessionregisetry (){
        return new SessionRegistryImpl();
    }
    
}
